package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.IndexSet;
import com.prs.crm.service.sys.IndexSetService;

public class IndexSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private IndexSet indexSet;
	private IndexSetService indexSetService;
	private String serCode;
	public IndexSet getIndexSet() {
		return indexSet;
	}
	public void setIndexSet(IndexSet indexSet) {
		this.indexSet = indexSet;
	}
	public IndexSetService getIndexSetService() {
		return indexSetService;
	}
	public void setIndexSetService(IndexSetService indexSetService) {
		this.indexSetService = indexSetService;
	}

	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	@Action("editIndexSet")
	public String editIndexSet(){
		this.indexSet=this.getIndexSetService().getIndexSet(serCode);
		return SUCCESS;
	}
	@Action(value="saveIndexSet",results={
			@Result(name="success",type="redirect",location="editIndexSet?serCode=${indexSet.getType()}"),
			@Result(name="error",type="chain",location="editIndexSet?serCode=${indexSet.getType()}")
	})
	public String saveIndexSet(){
		IndexSet is=this.getIndexSetService().getIndexSet("is01");
		if(is==null){
			is=new IndexSet();
			is.setType("is01");
			is.setDay(indexSet.getDay());
			this.getIndexSetService().save(is);
		}else{
			this.getIndexSetService().submit(is);
		}
		indexSet =is;
		return SUCCESS;
	}
}
